<template>
  <div class="app-container">
    <el-radio-group v-model="dataType" label-width="68px" @change="getTypeList">
      <el-radio-button label="1">用户</el-radio-button>
      <el-radio-button label="2">设备</el-radio-button>
    </el-radio-group>
    <div style="margin: 20px;"></div>
    <el-form ref="queryForm" label-width="80px" v-if="dataType == 1" :model="queryParams" size="small" :inline="true">
      <!-- <el-form-item label="治疗人" prop="treatName">
        <el-input v-model="queryParams.treatName"></el-input>
      </el-form-item> -->
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable v-model="queryParams.startTime" :picker-options="pickerOptions" type="date"
          value-format="yyyy-MM-dd" placeholder="请选择治疗开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable v-model="queryParams.endTime" type="date" :picker-options="pickerOptions"
          value-format="yyyy-MM-dd" placeholder="请选择治疗结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-form ref="queryForm" label-width="80px" v-if="dataType == 2" :model="queryEquParams" size="small"
      :inline="true">
      <!--      <el-form-item label="设备" prop="snCode">
        <el-input v-model="queryParams.snCode"></el-input>
      </el-form-item> -->
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable v-model="queryEquParams.startTime" :picker-options="pickerOptions" type="date"
          value-format="yyyy-MM-dd" placeholder="请选择治疗开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable v-model="queryEquParams.endTime" type="date" :picker-options="pickerOptions"
          value-format="yyyy-MM-dd" placeholder="请选择治疗结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 统计图 -->
    <CureNum :dataList="dataList"></CureNum>
  </div>
</template>
<script>
  import CureNum from './cureNum.vue';
  import {
    getStatistics
  } from '@/api/kenuo/record'
  export default {
    props: ['selectedItem'],
    data() {
      return {
        dataType: '1',
        queryParams: {
           treatorId: this.selectedItem.treatorId,
          //followUser: this.selectedItem.followUser,
          endTime: this.getDate(new Date()),
          startTime: this.getDate(new Date().getTime() - 365 * 24 * 3600 * 1000),
        },
        queryEquParams: {
          snCode: this.selectedItem.snCode,
          // snCode: this.selectedItem.snCode,
          endTime: this.getDate(new Date()),
          startTime: this.getDate(new Date().getTime() - 365 * 24 * 3600 * 1000),

        },
        pickerOptions: {
          disabledDate(time) {
            return (time.getTime() > Date.now()) || ((time.getTime() + 3600 * 1000 * 24 * 365) < Date.now());
          },
        },
        dataList: []
      };
    },
    components: {
      CureNum
    },
    created() {
      this.getList(this.queryParams)
    },
    methods: {
      getDate(now) {
        let year = new Date(now).getFullYear();
        let month = new Date(now).getMonth() + 1;
        let date = new Date(now).getDate();
        if (month < 10) month = "0" + month;
        if (date < 10) date = "0" + date;
        return year + "-" + month + "-" + date
      },
      getTypeList(e) {
        if (this.dataType == 1) {
          this.getList(this.queryParams)
        } else {
          this.getList(this.queryEquParams)
        }
      },
      /** 查询列表 */
      getList(params) {
        getStatistics(params).then(response => {
          this.dataList = response.data;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        if (this.dataType == 1) {
          this.getList(this.queryParams)
        } else {
          this.getList(this.queryEquParams)
        }

      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  }
</script>

<style>
</style>
